

/*
	 * To change this template, choose Tools | Templates
	 * and open the template in the editor.
	 */
function Initialize(){
	$( "#searchform" ).submit(
		function(){
			CheckSearchAction();
		}
	);
            
	var str = $("#user_search_keyword_hidden").val();
	if( "" == str ){
		$("#user_search_keyword").val("输入用户名、Email进行搜索...");
	}
	else{
		$("#user_search_keyword").val( str );
	}
}
	
function SetFocus(){
	//	var str = $("#keyword").val();
	//when search input box set to focus, clear the field
	$("#user_search_keyword").focus(
		function(){
			if( $("#user_search_keyword").val() == "输入用户名、Email进行搜索..." ){
				$("#user_search_keyword").val("");
			}
		}
	)
}

function CheckSearchAction(){
	if( $("#user_search_keyword").val() == "输入用户名、Email进行搜索..." ){
		$("#user_search_keyword").val("");
	}
}

function SortbySubmit( type ){
	//reset the sort by selector
	var sortby = $( "#sortby" ).val();
	if( sortby == type+"-asc" ){
		$( "#sortby" ).val( type+"-desc" );
	}
	else if( sortby == type+"-desc" ){
		$( "#sortby" ).val( type+"-asc" );
	}
	else{
		$( "#sortby" ).val( type+"-asc" );
	}
	$( "#sortform" ).submit();
}

//for review functions
function LoadSortbyClass(){
	var sortby = $( "#sortby" ).val();

        var id = sortby.substring( 0, sortby.indexOf("-") );
        var sortType = sortby.substring( sortby.indexOf("-")+1, sortby.length );

        $( "#sort"+id ).addClass( "selectedSortby" );
        if( sortType == "asc" ){
            $( "#sort"+id ).append( "<img src=\""+edp_static_domain_url+"image/arrow4.gif\" />" );
        }
        else{
            $( "#sort"+id ).append( "<img src=\""+edp_static_domain_url+"image/arrow5.gif\" />" );
        }
}

$(document).ready(function(){
	Initialize();
	SetFocus();

	LoadSortbyClass();

	$( "#sortadd_product_count" ).click(
		function(){
			SortbySubmit( "add_product_count" );
                        return false;
		}
	);
	$( "#sortadd_shop_count" ).click(
		function(){
			SortbySubmit( "add_shop_count" );
                        return false;
		}
	);
	$( "#sortreview_count" ).click(
		function(){
			SortbySubmit( "review_count" );
                        return false;
		}
	);
	$( "#sortcontribution" ).click(
		function(){
			SortbySubmit( "contribution" );
                        return false;
		}
	);
});

function addFriendInit(){
	//add friend
	$("a[class='add_friend']").click(function()
	{   
		var friendID=$(this).attr("name").split("_")[0];   
		var friendName=$(this).attr("name").split("_")[1]; 
		
		$.ajax(
		{
			type: 'get',
			url: edp_domain_url + 'ajax_log_info/?tiny=1',
			timeout: 5000,
			global:false,
			beforeSend: function()
			{
				$.blockUI(
				{ 
					message: '验证用户...',
					css: { padding:'5px',color:'#CC0000'}
				});
			},
			error: function()
			{
				$.blockUI(
				{ 
					message: '验证出错...',
					css: { padding:'5px',color:'#CC0000'}
				});
				$.unblockUI();
			},
		    success: function(data)
		    { 
				if(data==false)
				{   
					popupLogin($('#PopBox'),'添加好友');                
				}
				else
				{
					popupAddFriend($('#PopBox'),friendID,friendName);
				} 
				$.blockUI(
				{ 
					message: $('#PopBox'),    
					css: 
					{ 
						padding:        0,
						margin:         0,
						top:            '30%', 
		        		left:           '35%', 
						width:          '',
						textAlign:      '', 
						color:          '', 
						border:         '',
						backgroundColor:'',       				
						cursor:         'wait'				        
					 }
				}); 			  			 	 
			}
		}); 
	});
}
$(document).ready(function(){
	addFriendInit();
	
	//Function to refresh the validate image
	$("#virefresh").click(function()
	{
		$("#vimg").attr('src', edp_domain_url + 'vcode/?tiny='+Math.random());
	});
});
